#!/bin/sh

# post-checkout hook: compile python files to byte code

prev_HEAD="$1"
new_HEAD="$2"
new_branch="$3"

if [ "$new_branch" = 1 ]; then
   # if branch was changed - remove old bytecode files,
   # empty directories and outdated docs
   find . -name '*.py[co]' -delete &&
   for d in sqlobject/include/pydispatch sqlobject/include/tests; do
      if [ "`echo $d/*`" = "$d/*" ]; then rm -rf $d; fi
   done &&
   rm -rf docs/_build/html docs/html
fi &&

python    -m compileall -q -x '\.tox/.+' . &&
python -O -m compileall -q -x '\.tox/.+' .

exit 0
